package cn.cgy.fate;

import com.geccocrawler.gecco.annotation.PipelineName;
import com.geccocrawler.gecco.pipeline.Pipeline;
import org.apache.commons.lang3.StringUtils;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

@PipelineName("getResultSpiderPipeline")
public class GetResultSpiderPipeline implements Pipeline<GetResultSpider> {

    @Override
    public void process(GetResultSpider spider) {

        if (spider == null) {

            System.out.println("捉取开奖结果失败!");

            return;
        }

        StringBuffer sb = new StringBuffer();

        sb.append("本次幸运号码如下:<br><br>");

        for (int i = 0; i < ChoiceNumberForMoney.TICKET_GROUP; i++) {

            sb.append(ChoiceNumberForMoney.getTickByFate(i + 1));
        }

        sb.append("<br>======上一期双色球开奖信息=====" + "<br>");

        sb.append("第【" + spider.getPeriod() + "】期" + "<br>");

        sb.append(spider.getOpenInfo() + "<br>");

        sb.append("开奖号码:" + StringUtils.join(spider.getNumberList(), ",") + "<br>");

        sb.append("======上一期双色球开奖信息=====" + "<br>");

        sb.append("<br>Powered by CGY . Wish Good Luck For You");

        showGUI(sb.toString());
    }

    private void showGUI(String str) {

        JFrame.setDefaultLookAndFeelDecorated(true);

        JFrame frame = new JFrame("双色球");

        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        frame.setSize(450, 450);

        frame.setLocationRelativeTo(null); // Frame在窗体居中

        JLabel label = new JLabel("<html>" + str + "</html>");

        frame.getContentPane().add(label);

        frame.setVisible(true);
    }
}
